/*
 * 创建日期 2009-3-13
 *
 * 成都天和软件公司
 * 电话：028-85425861
 * 传真：028-85425861-8008
 * 邮编：610041 
 * 版权所有
 */
package  org.fantasy.common.grid.bean;

import java.util.List;

import  org.fantasy.common.util.StringUtil;

/**
 * 功能说明
 * 
 * @author: 王文成
 * @version: 1.0
 * @since 2009-3-13
 */
public class Column {
	/**
	 * 普通字符串
	 */
	public static final String DATA_TYPE_STRING = "string";

	/**
	 * 数字格式
	 */
	public static final String DATA_TYPE_NUMBER = "number";

	/**
	 * 百分比格式
	 */
	public static final String DATA_TYPE_PERCENT = "number-percent";

	/**
	 * 货币格式 1281,121,11.99
	 */
	public static final String DATA_TYPE_COMMA = "number-comma";

	/**
	 * 明细列 纵向显示一行的数据
	 */
	public static final String DATA_TYPE_DETAIL = "detail";

	/**
	 * 复选框 提供选择单选的功能
	 */
	public static final String DATA_TYPE_CHECKBOX = "checkbox";

	/**
	 * 参数ctx
	 */
	public static final String PARAM_CTX = "ctx";

	private String fieldName;

	private String fieldLabel;

	private String fieldValue;

	private String visible;

	private String dataType;

	private String click;

	private String width;

	private String percent;

	private String download;

	private String detail;

	private String isField;

	private String isSum;

	private String isStat;

	private String rowspan;

	private String colspan;

	private String scale;

	private String expression;

	private List<String> expParams;

	private List<String> valueParams;

	private String comment;

	private String export;

	private String desc;

	private String align;

	/**
	 * 字典
	 */
	private String dict;

	public String getFieldValue() {
		return fieldValue;
	}

	public void setFieldValue(String fieldValue) {
		this.fieldValue = fieldValue;
		this.valueParams = StringUtil.matchs(fieldValue, "#(\\w+)#", 1);
	}

	public String getIsStat() {
		return isStat;
	}

	public void setIsStat(String isStat) {
		this.isStat = isStat;
	}

	public String getIsSum() {
		return isSum;
	}

	public void setIsSum(String isSum) {
		this.isSum = isSum;
	}

	public String getDataType() {
		return dataType;
	}

	public boolean isPercentType() {
		return DATA_TYPE_PERCENT.equals(dataType);
	}

	public boolean isCommaType() {
		return DATA_TYPE_COMMA.equals(dataType);
	}

	public void setDataType(String dataType) {
		this.dataType = dataType;
	}

	public String getDownload() {
		return download;
	}

	public void setDownload(String download) {
		this.download = download;
	}

	public String getFieldLabel() {
		return fieldLabel;
	}

	public void setFieldLabel(String fieldLabel) {
		this.fieldLabel = fieldLabel;
	}

	/**
	 * @return 返回 fieldName。
	 */
	public String getFieldName() {
		return fieldName;
	}

	/**
	 * @param fieldName
	 *            要设置的 fieldName。
	 */
	public void setFieldName(String fieldName) {
		this.fieldName = fieldName;
	}

	/**
	 * @return 返回 percent。
	 */
	public String getPercent() {
		return percent;
	}

	/**
	 * @param percent
	 *            要设置的 percent。
	 */
	public void setPercent(String percent) {
		this.percent = percent;
	}

	/**
	 * @return 返回 visible。
	 */
	public String getVisible() {
		return visible;
	}

	/**
	 * @param visible
	 *            要设置的 visible。
	 */
	public void setVisible(String visible) {
		this.visible = visible;
	}

	/**
	 * @return 返回 click。
	 */
	public String getClick() {
		return click;
	}

	/**
	 * @param click
	 *            要设置的 click。
	 */
	public void setClick(String click) {
		this.click = click;
	}

	/**
	 * @return 返回 width。
	 */
	public String getWidth() {
		return width;
	}

	/**
	 * @param width
	 *            要设置的 width。
	 */
	public void setWidth(String width) {
		this.width = width;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getColspan() {
		return colspan;
	}

	public void setColspan(String colspan) {
		this.colspan = colspan;
	}

	public String getIsField() {
		return isField;
	}

	public boolean isField() {
		return !"false".equals(isField);
	}

	public void setIsField(String isField) {
		this.isField = isField;
	}

	public String getRowspan() {
		return rowspan;
	}

	public void setRowspan(String rowspan) {
		this.rowspan = rowspan;
	}

	public boolean isExpressionType() {
		return StringUtil.isValid(expression);
	}

	public int getScale(int defaultValue) {
		return StringUtil.isValid(scale) ? Integer.parseInt(scale) : defaultValue;
	}

	public String getScale() {
		return scale;
	}

	public void setScale(String scale) {
		this.scale = scale;
	}

	public String getExpression() {
		return expression;
	}

	public List<String> getExpParams() {
		return this.expParams;
	}

	public String getComment() {
		return comment;
	}

	public String getAlign() {
		return align;
	}

	public String getDict() {
		return dict;
	}

	public void setDict(String dict) {
		this.dict = dict;
	}

	public void setAlign(String align) {
		this.align = align;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public boolean isExport() {
		return !"false".equalsIgnoreCase(export);
	}

	public boolean isVisible() {
		return !"false".equalsIgnoreCase(visible);
	}

	public String getExport() {
		return export;
	}

	public void setExport(String export) {
		this.export = export;
	}

	public void setExpression(String expression) {
		this.expression = expression;
		this.expParams = StringUtil.matchs(expression, "#(\\w+)#", 1);
	}

	public boolean isNumberType() {
		String type = StringUtil.asString(dataType);
		return (type.indexOf(DATA_TYPE_NUMBER) != -1);
	}

	public boolean isDetailType() {
		return DATA_TYPE_DETAIL.equals(dataType);
	}

	public boolean isValueType() {
		return StringUtil.isValid(fieldValue);
	}
	
	public boolean isDictType() {
		return StringUtil.isValid(dict);
	}

	public boolean isCheckboxType() {
		return DATA_TYPE_CHECKBOX.equals(dataType);
	}

	public List<String> getValueParams() {
		return valueParams;
	}
	
	/**
	 * 是否是ID字段
	 * @return
	 */
	public boolean isID() {
		String name = String.valueOf(fieldName).toLowerCase();
		return name.endsWith("id");
	}

	/**
	 * 列唯一标识
	 */
	public String getId() {
		String id = StringUtil.asString(fieldName);
		if (!StringUtil.isValid(id)) {
			id = StringUtil.asString(fieldLabel);
		}
		return id.matches("\\w+") ? id : String.valueOf(id.hashCode());
	}
}
